/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;


import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Type;



@Entity
@Table(name = "\"javeriana.sc.cc\".\"t_material\"" )
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Material.findAll", query = "SELECT m FROM Material m"),
    @NamedQuery(name = "Material.findByTypeMaterial", query = "SELECT m FROM Material m WHERE m.typematerial = :typematerial")})

public class Material implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic (optional = false)
    @Column (name = "typematerial")
    private String typematerial;
    @JoinTable(name = "\"javeriana.sc.cc\".\"t_supplierXmaterial\"", joinColumns = {
            @JoinColumn(name = "typematerial", referencedColumnName = "typematerial")}, inverseJoinColumns = {
            @JoinColumn(name = "pymeindentification", referencedColumnName = "pymeidentification"),
            @JoinColumn(name = "supplierindentification", referencedColumnName = "supplierindentification")})
    @LazyCollection(LazyCollectionOption.FALSE)
    @ManyToMany
    //@CollectionId(columns = @Column(name ="pymeidentification"), type = @Type(type="int"),generator = "native" )
    private List<SupplierXpyme> supplierXpymeList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "material")
    private List<Supplier> supplierList;
    @OneToMany(mappedBy = "material")
    private List<Product> productList;

    public Material() {
    }

    public Material(String typematerial) {
        this.typematerial = typematerial;
    }

    public String getTypematerial() {
        return typematerial;
    }

    public void setTypematerial(String typematerial) {
        this.typematerial = typematerial;
    }

    @XmlTransient
    public List<SupplierXpyme> getSupplierXpymeList() {
        return supplierXpymeList;
    }

    public void setSupplierXpymeList(List<SupplierXpyme> supplierXpymeList) {
        this.supplierXpymeList = supplierXpymeList;
    }

    @XmlTransient
    public List<Supplier> getTSupplierList() {
        return supplierList;
    }

    public void setTSupplierList(List<Supplier> supplierList) {
        this.supplierList = supplierList;
    }

    @XmlTransient
    public List<Product> getTProductList() {
        return productList;
    }

    public void setTProductList(List<Product> productList) {
        this.productList = productList;
    }
    
    
      
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (typematerial != null ? typematerial.hashCode() : 0);
        return hash;
    }
    
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Material)) {
            return false;
        }
        Material other = (Material) object;
        if ((this.typematerial == null && other.typematerial != null) || (this.typematerial != null && !this.typematerial.equals(other.typematerial))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Material[ typematerial=" + typematerial + " ]";
    }
}
